#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_solvhyper.info <<'%EOF%'
   rsp_solvhyper
   -------------
   Molecule:         H2O
   Wave Function:    SCF / ANO (Atombasis)
   Test Purpose:     Non-equilibrium solvation first hyper-
                     polarizabilities
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_solvhyper.mol <<'%EOF%'
ATOMBASIS
Calculation of non-equilibrium solvation first hyperpolarizabilities

    2    2  X  Z
        8.    1 Basis=ano-1 5 4 3 0
O     0.0  1.0 0.0
        1.    1 Basis=ano-1 4 3 0
H     1.4344154111 2.1075628725 0.0
H    -1.4344154111 2.1075628725 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_solvhyper.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
*ONEINT
.SOLVENT
 7
**WAVE FUNCTIONS
.HF
*SOLVENT
.INERSI
 78.45 1.8
.MAX L
 7
.CAVITY
 4.4784
**RESPONSE
*QUADRATIC
.DIPLEN
.SHG
.FREQUENCY
2
 0.0 0.0656
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_solvhyper.check
cat >>rsp_solvhyper.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Integral setup
CRIT1=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
CRIT1b=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "two-electron integrals are transformed to P-supermatrix elements" $log | wc -l`
CRIT2b=`$GREP "Fock matrices are calculated directly and in parallel without use of integrals on disk" $log |wc -l`
CRIT3=`$GREP "One\-electron RLM integrals calculated\." $log | wc -l`
CRIT4=`$GREP "Maximum L quantum number\: * 7" $log | wc -l`
CRIT5=`$GREP "All symmetries saved on file\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT1b \+ $CRIT2b`
CTRL[1]=5
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "O * 1 * 8\.0000 * 61 * 32 * \[14s9p4d\|5s4p3d\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 20 * 13 * \[8s4p\|4s3p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 10\.0000 * 101 * 58" $log | wc -l`
CRIT4=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[2]=4
ERROR[2]="ATOMBASIS NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * 1\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 1\.4344154111" $log | wc -l`
CRIT6=`$GREP "5 * y * 2\.1075628725" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "7 * x * \-1\.4344154111" $log | wc -l`
CRIT9=`$GREP "8 * y * 2\.1075628725" $log | wc -l`
CRIT10=`$GREP "9 * z * (0| )\.0000000000" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[3]=10
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 3 * 2 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 25 * 17 * 10 * 6" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Cavity center
CRIT1=`$GREP "Cavity center \(center of mass\)\: * (0| )\.000000 * 1\.12395[0-9] * (0| )\.000000" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="CAVITY CENTER NOT CORRECT"

# Solvation model
CRIT1=`$GREP "SOLVATION MODEL\: molecule is in a cavity in a dielectric medium\," $log | wc -l`
CRIT2=`$GREP "static diel\. const\. \= * 78\.450000" $log | wc -l`
CRIT3=`$GREP "cavity dimensions * \= * 4\.478400 * 4\.478400 * 4\.478400" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[6]=3
ERROR[6]="SOLVATION MODEL NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-76\.07014607148[0-9]" $log | wc -l`
TEST[7]=`expr	$CRIT1`
CTRL[7]=1
ERROR[7]="SCF ENERGY NOT CORRECT"

# Response setup
CRIT1=`$GREP "Quadratic Response calculation" $log | wc -l`
CRIT2=`$GREP "First hyperpolarizability calculation \: HYPCAL\= T" $log | wc -l`
CRIT3=`$GREP "Spin of operator A \, ISPINA\= * 0" $log | wc -l`
CRIT4=`$GREP "Spin of operator B \, ISPINB\= * 0" $log | wc -l`
CRIT5=`$GREP "Spin of operator C \, ISPINC\= * 0" $log | wc -l`
CRIT6=`$GREP "2 B\-frequencies * (0| )\.000000(D|E)\+00 * 6\.560000(D|E)\-02" $log | wc -l`
CRIT7=`$GREP "2 C\-frequencies * (0| )\.000000(D|E)\+00 * 6\.560000(D|E)\-02" $log | wc -l`
CRIT8=`$GREP "Non\-equilibrium solvent model requested * \: INERSI \= T" $log | wc -l`
CRIT9=`$GREP "Static dielectric constant * \: EPSTAT *\= 78\.4500" $log | wc -l`
CRIT10=`$GREP "Optical dielectric constant * \: EPSOL *\= * 1\.8000" $log | wc -l`
CRIT11=`$GREP "Second harmonic generation.* SHG" $log | wc -l`
CRIT12=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT13=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT14=`$GREP "1 C OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14`
CTRL[8]=20
ERROR[8]="QR CALCULATION SETUP NOT CORRECT"

# linear response
CRIT1=`$GREP "Value of linear response.*\: * 8\.7197" $log | wc -l`
CRIT2=`$GREP "Value of linear response.*\: * 8\.8231" $log | wc -l`
CRIT3=`$GREP "Value of linear response.*\: * 9\.3435" $log | wc -l`
CRIT4=`$GREP "Value of linear response.*\: * 9\.4338" $log | wc -l`
CRIT5=`$GREP "Value of linear response.*\: * 8\.2756" $log | wc -l`
CRIT6=`$GREP "Value of linear response.*\: * 8\.4023" $log | wc -l`
TEST[9]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[9]=6
ERROR[9]="LINEAR RESPONSE NOT CORRECT"

# First hyperpolarizabilities
CRIT1=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(Y\;Y\,Y\) \= * 1\.35[01]" $log | wc -l`
CRIT2=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(Y\;Y\,Y\) \= * 1\.(499|500)" $log | wc -l`
CRIT3=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(X\;X\,Y\) \= * \-9\.147" $log | wc -l`
CRIT4=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(X\;X\,Y\) \= * \-10\.162" $log | wc -l`
CRIT5=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(Z\;Z\,Y\) \= * 2\.931" $log | wc -l`
CRIT6=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(Z\;Z\,Y\) \= * 2\.92[12]" $log | wc -l`
CRIT7=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(X\;Y\,X\) \= beta\(X\,X\,Y\)" $log | wc -l`
CRIT8=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(X\;Y\,X\) \= beta\(X\,X\,Y\)" $log | wc -l`
CRIT9=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(Y\;X\,X\) \= beta\(X\,X\,Y\)" $log | wc -l`
CRIT10=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(Y\;X\,X\) \= * \-10\.059" $log | wc -l`
CRIT11=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(Z\;Y\,Z\) \= beta\(Z\,Z\,Y\)" $log | wc -l`
CRIT12=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(Z\;Y\,Z\) \= beta\(Z\,Z\,Y\)" $log | wc -l`
CRIT13=`$GREP "\@ B\-freq \= (0| )\.000000 * C\-freq \= (0| )\.000000 * beta\(Y\;Z\,Z\) \= beta\(Z\,Z\,Y\)" $log | wc -l`
CRIT14=`$GREP "\@ B\-freq \= (0| )\.065600 * C\-freq \= (0| )\.065600 * beta\(Y\;Z\,Z\) \= * 3\.93[45]" $log | wc -l`
TEST[10]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14`
CTRL[10]=14
ERROR[10]="FIRST HYPERPOLARIZABILITIES NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9 10
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
